"""
This is the default client to be used for test modules in this directory
"""

from coffeetalk.client import iotpclient
from coffeetalk.protocol import iotypes
from coffeetalk.utilities import iologger

class TestClient(iotpclient.IOTPClient):
    
    def __init__(self):
        
        self.log = iologger.IONullLogger()
                
        self.connectionconfig = iotypes.Connection(name='Connection')
        self.connectionconfig.username = 'TestClient'
        self.connectionconfig.password = 'testing123'
        self.connectionconfig.host = '127.0.0.1'
        self.connectionconfig.port = 9091        
        self.connectionconfig.userclass = 'System'
    
    def connect(self):
        iotpclient.IOTPClient.__init__(self, config=self.connectionconfig,log=self.log)
        iotpclient.IOTPClient.connect(self)
        
    def on_login(self):
        print 'Successful login!'
    
    def on_bad_login(self):
        print 'Bad Login'
    
    def current_error(self,env,path,request,err,**kwargs):
        if 'Current' in kwargs:
            current = kwargs['Current']
            print 'Error in %s' % current
            
    def on_success(self,env,path,**kwargs):
        print 'Success!'
        print 'Path: ' + path
        print str(kwargs)
        
    def on_error(self,env,path,request,err,**kwargs):
        print 'Error!'
        print 'Path: ' + path
        print str(err)
        print str(kwargs)
        
class TestUserClient(TestClient):
    
    def __init__(self,username='TestUserClient'):
        TestClient.__init__(self)
        
        self.log = iologger.IOLogger()
        
        logconfig = iologger.IOLoggerSettings()
        logconfig.Name.value = username
        self.log.standardlogging = iologger.IOStdLogger(logconfig=logconfig)
    
        self.connectionconfig.username = username
        self.connectionconfig.password = 'testing456'
        self.connectionconfig.port = 5050
        self.connectionconfig.userclass = 'Users'
        
        
class TestSystemClient(TestClient):
    
    def __init__(self,username='TestSystemClient'):
        TestClient.__init__(self)
        
        self.log = iologger.IOLogger()
        
        logconfig = iologger.IOLoggerSettings()
        logconfig.Name.value = username
        self.log.standardlogging = iologger.IOStdLogger(logconfig=logconfig)
    
        self.connectionconfig.username = username
    
if __name__ == '__main__':
    
    chatter = TestUserClient()
    chatter.connect()